home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / uuconf.subproj / callin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  5.0 KB  |  196 lines

  1. /* callin.c
  2.    Check a login name and password against the UUCP password file.
  3.  
  4.    Copyright (C) 1992, 1993, 1995 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP uuconf library.
  7.  
  8.    This library is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU Library General Public License
  10.    as published by the Free Software Foundation; either version 2 of
  11.    the License, or (at your option) any later version.
  12.  
  13.    This library is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    Library General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU Library General Public
  19.    License along with this library; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #include "uucnfi.h"
  27.  
  28. #if USE_RCS_ID
  29. const char _uuconf_callin_rcsid[] = "$Id: callin.c,v 1.11 1995/06/21 19:21:42 ian Rel $";
  30. #endif
  31.  
  32. #include <errno.h>
  33.  
  34. static int ipcheck P((pointer pglobal, int argc, char **argv,
  35.               pointer pvar, pointer pinfo));
  36.  
  37. struct sinfo
  38. {
  39.   int (*pcmpfn) P((int, pointer, const char *));
  40.   pointer pinfo;
  41.   boolean ffound;
  42.   boolean fmatched;
  43. };
  44.  
  45. /* Check a login name and password against the UUCP password file.
  46.    This looks at the Taylor UUCP password file, but will work even if
  47.    uuconf_taylor_init was not called.  It accepts either spaces or
  48.    colons as field delimiters.  */
  49.  
  50. int
  51. uuconf_callin (pglobal, pcmpfn, pinfo)
  52.      pointer pglobal;
  53.      int (*pcmpfn) P((int, pointer, const char *));
  54.      pointer pinfo;
  55. {
  56.   struct sglobal *qglobal = (struct sglobal *) pglobal;
  57.   int iret;
  58.   char **pz;
  59.   struct uuconf_cmdtab as[1];
  60.   struct sinfo s;
  61.   char *zline;
  62.   size_t cline;
  63.  
  64.   /* If we have no password file names, fill in the default name.  */
  65.   if (qglobal->qprocess->pzpwdfiles == NULL)
  66.     {
  67.       char ab[sizeof NEWCONFIGLIB + sizeof PASSWDFILE - 1];
  68.  
  69.       memcpy ((pointer) ab, (pointer) NEWCONFIGLIB,
  70.           sizeof NEWCONFIGLIB - 1);
  71.       memcpy ((pointer) (ab + sizeof NEWCONFIGLIB - 1), (pointer) PASSWDFILE,
  72.           sizeof PASSWDFILE);
  73.       iret = _uuconf_iadd_string (qglobal, ab, TRUE, FALSE,
  74.                   &qglobal->qprocess->pzpwdfiles,
  75.                   qglobal->pblock);
  76.       if (iret != UUCONF_SUCCESS)
  77.     return iret;
  78.     }
  79.  
  80.   as[0].uuconf_zcmd = NULL;
  81.  
  82.   s.pcmpfn = pcmpfn;
  83.   s.pinfo = pinfo;
  84.   s.ffound = FALSE;
  85.   s.fmatched = FALSE;
  86.  
  87.   zline = NULL;
  88.   cline = 0;
  89.  
  90.   iret = UUCONF_SUCCESS;
  91.  
  92.   for (pz = qglobal->qprocess->pzpwdfiles; *pz != NULL; pz++)
  93.     {
  94.       FILE *e;
  95.  
  96.       e = fopen (*pz, "r");
  97.       if (e == NULL)
  98.     {
  99.       if (FNO_SUCH_FILE ())
  100.         continue;
  101.       qglobal->ierrno = errno;
  102.       iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
  103.       break;
  104.     }
  105.  
  106.       qglobal->ilineno = 0;
  107.  
  108.       iret = UUCONF_SUCCESS;
  109.  
  110.       while (getline (&zline, &cline, e) > 0)
  111.     {
  112.       char *z0, *z1;
  113.  
  114.       ++qglobal->ilineno;
  115.  
  116.       /* We have a few hacks to make Unix style passwd files work.
  117.          1) We turn the first two colon characters into spaces.
  118.          2) If the colon characters are adjacent, we assume there
  119.             is no password, and we skip the entry.
  120.          3) If the password between colon characters contains a
  121.             space, we assume that it has been disabled, and we
  122.         skip the entry.  */
  123.       z0 = strchr (zline, ':');
  124.       if (z0 != NULL)
  125.         {
  126.           *z0 = ' ';
  127.           z1 = strchr (z0, ':');
  128.           if (z1 != NULL)
  129.         {
  130.           if (z1 - z0 == 1)
  131.             continue;
  132.           *z1 = '\0';
  133.           if (strchr (z0 + 1, ' ') != NULL)
  134.             continue;
  135.         }
  136.         }          
  137.       iret = uuconf_cmd_line (pglobal, zline, as, (pointer) &s,
  138.                   ipcheck, 0, (pointer) NULL);
  139.       if ((iret & UUCONF_CMDTABRET_EXIT) != 0)
  140.         {
  141.           iret &=~ UUCONF_CMDTABRET_EXIT;
  142.           if (iret != UUCONF_SUCCESS)
  143.         iret |= UUCONF_ERROR_LINENO;
  144.           break;
  145.         }
  146.  
  147.       iret = UUCONF_SUCCESS;
  148.     }
  149.  
  150.       (void) fclose (e);
  151.  
  152.       if (iret != UUCONF_SUCCESS || s.ffound)
  153.     break;
  154.     }
  155.  
  156.   if (zline != NULL)
  157.     free ((pointer) zline);
  158.  
  159.   if (iret != UUCONF_SUCCESS)
  160.     {
  161.       qglobal->zfilename = *pz;
  162.       iret |= UUCONF_ERROR_FILENAME;
  163.     }
  164.   else if (! s.ffound || ! s.fmatched)
  165.     iret = UUCONF_NOT_FOUND;
  166.  
  167.   return iret;
  168. }
  169.  
  170. /* This is called on each line of the file.  It checks to see if the
  171.    login name from the file is the one we are looking for.  If it is,
  172.    it sets ffound, and then sets fmatched according to whether the
  173.    password matches or not.  */
  174.  
  175. static int
  176. ipcheck (pglobal, argc, argv, pvar, pinfo)
  177.      pointer pglobal;
  178.      int argc;
  179.      char **argv;
  180.      pointer pvar;
  181.      pointer pinfo;
  182. {
  183.   struct sinfo *q = (struct sinfo *) pinfo;
  184.  
  185.   if (argc != 2)
  186.     return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
  187.  
  188.   if (! (*q->pcmpfn) (0, q->pinfo, argv[0]))
  189.     return UUCONF_CMDTABRET_CONTINUE;
  190.  
  191.   q->ffound = TRUE;
  192.   q->fmatched = (*q->pcmpfn) (1, q->pinfo, argv[1]) != 0;
  193.  
  194.   return UUCONF_CMDTABRET_EXIT;
  195. }
  196.